Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
S2Cell::Decode reads a raw 64-bit S2CellId from the buffer and hands it straight to the S2Cell constructor, and S2CellUnion::Decode stores each decoded id the same way, without either one calling is_valid(). Those bytes come from whatever serialized data the caller is decoding, so an id with face bits 6 or 7, or one with no level marker bit such as 0, gets through and leaves the cell with face_ outside 0..5 or a level of -2. From there GetRectBound() looks up S2::GetUAxis(face_), which indexes the six-entry kFaceUVWAxes table out of bounds, and the bad level feeds an out-of-range shift in IJLevelToBoundUV; S2CellUnion reaches the same code because its region methods build an S2Cell from every stored id. I noticed it while comparing the region decoders, since S2LatLngRect::Decode and S2PointRegion::Decode already return false on invalid input and these two were the outliers, and decoding the eight bytes ff ff ff ff ff ff ff ff followed by GetRectBound() under UBSan reports "index 7 out of bounds for type 'const double[6][3][3]'" at s2coords.h:481. The fix makes both decoders reject any id that fails S2CellId::is_valid(), so every encoding produced by Encode() still round-trips unchanged and the check stays inside the decoders instead of relying on each caller. I added DecodeRejectsInvalidCellId tests to s2cell_test and s2cell_union_test, which fail before the change and pass after, and the full test suite is green locally.